package com.kgc.scd.config;

import com.kgc.scd.interceptor.TokenPermissionInterceptor;
import com.kgc.scd.resolver.MyDefineShopUserResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.validation.MessageCodesResolver;
import org.springframework.validation.Validator;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.config.annotation.*;

import java.util.List;

/**
 * Created On : 2022/11/4 0004.
 * <p>
 * Author : shiguangchuan
 * <p>
 * Description: 自定义webmvc配置类，可以实现手动添加拦截器，解析器操作
 */
@Configuration
public class MyDefineWebMvcConfig implements WebMvcConfigurer {

    /**
     * @author : shiguangchuan
     * @date   : 2022/11/4 0004
     * @param  : []
     * @return : com.kgc.scd.interceptor.TokenPermissionInterceptor
     * @description : 手动创建请求token许可拦截器对象，放入容器，方便加入系统拦截器组中
     */
    @Bean
    public TokenPermissionInterceptor tokenPermissionInterceptor(){
        return new TokenPermissionInterceptor();
    }

    /**
     * @author : shiguangchuan
     * @date   : 2022/11/4 0004
     * @param  : []
     * @return : com.kgc.scd.resolver.MyDefineUserResolver
     * @description : 手动创建自定义请求用户解析器对象，放入容器，方便加入到系统中的解析器中
     */
    @Bean
    public MyDefineShopUserResolver myDefineShopUserResolver(){
        return new MyDefineShopUserResolver();
    }

    @Override
    public void configurePathMatch(PathMatchConfigurer pathMatchConfigurer) {

    }

    @Override
    public void configureContentNegotiation(ContentNegotiationConfigurer contentNegotiationConfigurer) {

    }

    @Override
    public void configureAsyncSupport(AsyncSupportConfigurer asyncSupportConfigurer) {

    }

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer defaultServletHandlerConfigurer) {

    }

    @Override
    public void addFormatters(FormatterRegistry formatterRegistry) {

    }

    @Override
    public void addInterceptors(InterceptorRegistry interceptorRegistry) {

        // 手动添加自定义拦截器到系统拦截器组中，才可以生效，否则不生效
        interceptorRegistry.addInterceptor(tokenPermissionInterceptor()).addPathPatterns("/**");

    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry resourceHandlerRegistry) {

    }

    @Override
    public void addCorsMappings(CorsRegistry corsRegistry) {

    }

    @Override
    public void addViewControllers(ViewControllerRegistry viewControllerRegistry) {

    }

    @Override
    public void configureViewResolvers(ViewResolverRegistry viewResolverRegistry) {

    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> list) {

        // 手动将容器中自定义请求用户解析器，加入到系统解析器结合中
        list.add(myDefineShopUserResolver());

    }

    @Override
    public void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> list) {

    }

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> list) {

    }

    @Override
    public void extendMessageConverters(List<HttpMessageConverter<?>> list) {

    }

    @Override
    public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> list) {

    }

    @Override
    public void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> list) {

    }

    @Override
    public Validator getValidator() {
        return null;
    }

    @Override
    public MessageCodesResolver getMessageCodesResolver() {
        return null;
    }
}
